package cn.iocoder.yudao.module.resource.api.enums;

import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;

@AllArgsConstructor
@ToString
public enum UserTimeTransactionTypeEnum implements IntArrayValuable {
    CONSUME(-1, "用户消耗"),
    PURCHASE(1, "用户充值"),
    NEW_USER_GIVE(2, "新用户赠送"),
    OPERATOR_RECHARGE(3, "运营充值"),
    ;

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserTimeTransactionTypeEnum::getValue).toArray();

    /**
     * 类型
     */
    private final Integer value;
    /**
     * 类型名
     */
    private final String name;

    public static UserTimeTransactionTypeEnum valueOf(Integer value) {
        return ArrayUtil.firstMatch(userType -> userType.getValue().equals(value), UserTimeTransactionTypeEnum.values());
    }

    @Override
    public int[] array() {
        return ARRAYS;
    }

    @JsonValue
    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }
}
